#include <iostream>

using namespace std;

#include <map>

class Solution {
    map<char, int> mappings;
public:
    Solution() {
        mappings.insert(map<char, int>::value_type('I', 1));
        mappings.insert(map<char, int>::value_type('V', 5));
        mappings.insert(map<char, int>::value_type('X', 10));
        mappings.insert(map<char, int>::value_type('L', 50));
        mappings.insert(map<char, int>::value_type('C', 100));
        mappings.insert(map<char, int>::value_type('D', 500));
        mappings.insert(map<char, int>::value_type('M', 1000));
    }

    int romanToInt(string s) {
        int res = 0;
        int i;
        for (i = 0; i < s.length()-1; ++i) {
            if (mappings[s[i]] < mappings[s[i+1]]) {
                res -= mappings[s[i]];
            } else {
                res += mappings[s[i]];
            }
        }
        res += mappings[s[i]];
        return res;
    }
};

int main() {
    std::cout << Solution().romanToInt("MCMXCIV") << endl;
    return 0;
}